import { createRouter, createWebHistory } from 'vue-router'
import ClientView from '../views/ClientView.vue'
import ModifyPasswordView from '../views/ModifyPasswordView.vue'
import AdministratorsInfoView from '../views/AdministratorsInfoView.vue'
import WhdManage from '../views/WhdManage'
import WhdInsert from '../components/WhdInsert'
import WorkerView from "@/views/WorkerView";
import SalaryView from "@/views/SalaryView";

const routes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/LoginView.vue')
  },
  {
    path: '/client',
    name: 'client',
    component: ClientView

  },
  {
    path: '/modifypassword',
    name: 'modifypassword',
    component: ModifyPasswordView
  },
  {
    path: '/administratorsinfo',
    name: 'administratorsinfo',
    component: AdministratorsInfoView
  },
  {
    path: '/WhdManage',
    name: WhdManage,
    component: () => import("@/views/WhdManage")
  },
  {
    path: '/WhdInsert',
    name: WhdInsert,
    component: () => import("@/components/WhdInsert")
  },
  {
    path: '/WorkerView',
    name:WorkerView,
    component: () =>import("../views/WorkerView")
  },
  {
    path:'/Salary',
    name:SalaryView,
    component: () =>import("../views/SalaryView")
  },
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})


router.beforeEach((to, from,  next) => {
  if(to.path === '/login') return next(); //直接放行
  //验证身份
  let loginUser = sessionStorage.getItem('loginUser');
  if(!loginUser){
    return next('/login');
  }
  next();
})
export default router
